package com.forum.module.system.convert.user;

import com.forum.framework.common.util.colletion.CollectionUtils;
import com.forum.framework.common.util.object.BeanUtils;
import com.forum.framework.security.core.LoginUser;
import com.forum.module.system.controller.admin.user.vo.user.LoginUserInfoRespVO;
import com.forum.module.system.controller.admin.user.vo.user.UserRespVO;
import com.forum.module.system.controller.admin.user.vo.user.UserSimpleRespVO;
import com.forum.module.system.dal.dataobject.user.UserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author zihan.ouyang
 */
@Mapper
public interface UserConvert {
    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    default List<UserRespVO> covertList(List<UserDO> list) {
        return CollectionUtils.convertList(list, this::covert);
    }

    default UserRespVO covert(UserDO userDO) {
        return BeanUtils.toBean(userDO, UserRespVO.class);
    }

    default LoginUserInfoRespVO covert(LoginUser loginUser) {
        return BeanUtils.toBean(loginUser, LoginUserInfoRespVO.class);
    }

    default List<UserSimpleRespVO> covertSimpleList(List<UserDO> list) {
        return CollectionUtils.convertList(list, user ->
                BeanUtils.toBean(user, UserSimpleRespVO.class)
        );
    }
}
